feat: cap envelope assignment at Ready to Assign (Issue #7)#15
Merged
Conversation
Prevent assigning more to an envelope than actually exists. "Money that exists" is Ready to Assign = net worth across all real accounts minus envelopes, so savings-held funds count even when the budget-host account is empty; the gate is the net-worth pool, never a single account's balance. - Extract getReadyToAssign() into server/utils/budgetData.ts as the single source of truth, shared by GET /api/budget and the assign availability gate - Reject over-assignment in budget/assign.post.ts (400, no journal write) with a clear "Can't assign $X — only $Y left to assign." message - Add a client-side guard + toast in budget.vue for instant feedback (server stays authoritative) - Overspending an envelope and inter-envelope transfers stay unrestricted (the coverage mechanism), only assigning beyond the pool is blocked - Document the single-host / availability model decision in the design doc Verified end-to-end against a running dev server: over-assign rejected with no write, within-budget accepted, savings-backed assignment accepted with an empty checking account, epsilon boundary, and transfers not gated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7
What & why
You could assign more to an envelope than actually existed — there was no availability check on assignment. This adds one: you can't budget money that doesn't exist.
"Money that exists" = Ready to Assign = net worth across all real accounts − envelopes, so funds physically held in savings count even when the budget-host account (checking) is empty. The gate is the net-worth pool, never a single account's balance — which is exactly the scenario in #7 ("budget in an envelope, money kept in savings").
The product owner clarified the model (this is YNAB-faithful, not the original "just show a red number" idea):
Changes
server/utils/budgetData.ts(new) —getReadyToAssign()+READY_TO_ASSIGN_EPSILON, the single source of truth for the RTA pool.GET /api/budgetis refactored to use it (figures unchanged), so the report and the gate can never disagree.server/api/budget/assign.post.ts— rejects an over-assignment with400 "Can't assign $X — only $Y left to assign."and no journal write.pages/budget.vue— client-side guard + toast for instant feedback (server stays authoritative).AI-MAP.md..kiro/specs/enforce-budget-availability/.Decision recorded
Single budget host is intentional; multi-account envelope hosting is not a goal. A negative
…:budget:unallocated(from assigning savings-backed money) is numerically correct and intentionally not surfaced.Tests & verification
server/api/__tests__/budget-assign.test.ts— over-assign vs net worth rejected (single + summed envelopes), within/boundary accepted, savings-backed assignment accepted with empty checking (net-worth basis).npx nuxi typecheckclean.🤖 Generated with Claude Code